class RegistrationsController < Devise::RegistrationsController
  before_filter :update_sanitized_params, if: :devise_controller?

  def create
    params.permit!
    user = User.new(params[:user])
    respond_to do |format|
      # binding.pry
      if user.save
        format.html {redirect_to '/'}
        format.js
      else
        format.html {redirect_to '/'}
        format.js {render js: "alert('注册失败！')"}
      end
    end
  end

  def update_sanitized_params
    devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:name, :email, :password, :password_confirmation)}
    devise_parameter_sanitizer.for(:account_update) {|u| u.permit(:name, :email, :password, :password_confirmation, :current_password)}
  end

end